package com.colin.aiyi.ui;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.TextView;

import com.colin.aiyi.R;
import com.colin.aiyi.dao.ImpxUtils.ImpMsgRead;
import com.colin.aiyi.entity.User;
import com.colin.aiyi.utils.SharePreferenceUtil;
import com.colin.aiyi.utils.TimeUtil;

import java.util.Date;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by hl on 2017/6/14.
 */

public class AcMsgDetails extends BaseActivity {
    @BindView(R.id.text_banner_left)
    TextView textBannerLeft;
    @BindView(R.id.text_banner_title)
    TextView textBannerTitle;
    @BindView(R.id.text_banner_rigth)
    TextView textBannerRigth;
    @BindView(R.id.text_msg_flag)
    TextView textMsgFlag;
    @BindView(R.id.frame_layout)
    FrameLayout frameLayout;
    @BindView(R.id.text_msg_title)
    TextView textMsgTitle;
    @BindView(R.id.text_msg_time)
    TextView textMsgTime;
    @BindView(R.id.text_msg_desc)
    TextView textMsgDesc;
    private String title;
    private String content;
    private long pushTime;
    private int id;
    private boolean isRead;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.ac_msg_details);
        ButterKnife.bind(this);
        textBannerTitle.setText("消息详情");
        textBannerLeft.setOnClickListener(this);
        isRead=getIntent().getBooleanExtra("isRead",false);
        id =getIntent().getIntExtra("id",0);
        title =getIntent().getStringExtra("title");
        content=getIntent().getStringExtra("content");
        pushTime=getIntent().getLongExtra("pushTime",0);
        bindView();
        user= SharePreferenceUtil.getObject(this,User.class);
        if (user!=null&&!isRead)
        {
            user.setId(id);
            new ImpMsgRead().getObject(user);
        }
    }

    private void bindView() {
        textMsgFlag.setVisibility(View.GONE);
        textMsgTitle.setText(title);
        textMsgDesc.setText(content);
        textMsgTime.setText(TimeUtil.getTime(new Date(pushTime)));
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.text_banner_left:
                onBackPressed();
                break;
        }
    }

    @Override
    public void onBackPressed() {
        setResult(0x312,new Intent());
        super.onBackPressed();
    }
}
